package com.shop.controller;

import com.shop.service.UserInfoService;
import com.shop.vo.Result;
import com.shop.vo.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @PutMapping("/updateArticleNumber/{authorId}/{changeNum}")
    public Result updateArticleNumber(@PathVariable("authorId") Integer authorId, @PathVariable("changeNum") Integer changeNum) {
        System.out.println(authorId + "" + changeNum);
        int num = userInfoService.updateArticleNumber(authorId, changeNum);
        Result r = new Result();
        if (num > 0) {
            r.setCode(StatusCode.OK);
            r.setFlag(true);
            r.setMessage("修改该作者的文章数量成功");
        } else {
            r.setCode(StatusCode.ERROR);
            r.setFlag(false);
            r.setMessage("修改该作者的文章数量失败");
        }
        return r;
    }
}
